package com.hnkywl.sts.action.kcgl;

import com.hnkywl.sts.entity.sys.Bm;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.entity.xsgl.Xsd;
import com.hnkywl.sts.service.base.BmService;
import com.hnkywl.sts.service.kcgl.CkshService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.YgService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-5-3
 * Time: 上午11:00
 * To change this template use File | Settings | File Templates.
 */
@Namespaces({@Namespace("/kcgl/cksh"), @Namespace("/kcgl/slsh")})
public class CkshAction extends SimpleActionSupport {
    private CkshService ckshService;
    private BmService bmService;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //查询条件
    private String xsdh;
    private Long khId;
    private Long xsgsId;
    private Long ckId;
    private Date zdrqStart;
    private Date zdrqEnd;
    private Date cksjStart;
    private Date cksjEnd;
    private Date startTime;
    private Date endTime;
    private Long gsId;
    private Long zggsId;
    private Yg yg;
    private Xsd xsd;
    private Date startDate;
    private Bm xsdhm;
    private Long xsdId;
    private String ckshbz;
    private String yck = "wck";
    private String wzbm;
    private String yps;

    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;

    @Action("ckshList")
    public void ckshList() {
        this.renderJson(this.ckshService.findAllCksh(wzbm, xsdh, khId, ckId, zdrqStart, zdrqEnd, xsgsId, yck, yps, page, rows, cksjStart, cksjEnd));
    }

    @Action("slshList")
    public void slshList() {
        this.renderJson(this.ckshService.findAllSlsh(wzbm, xsdh, khId, ckId, zdrqStart, zdrqEnd, xsgsId, yck, page, rows));
    }

    @Action("cksh")
    public String cksh() {
        Calendar calendar = Calendar.getInstance();
        //得到月初
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        startTime = calendar.getTime();
        //得到月末
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        endTime = calendar.getTime();

        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }


    @Action("slsh")
    public String slsh() {
        Calendar calendar = Calendar.getInstance();
        //得到月初
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        startTime = calendar.getTime();
        //得到月末
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        endTime = calendar.getTime();

        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    @Actions({@Action("cksh_content"), @Action("cksh_detail"), @Action("slsh_detail")})
    public String ckshContent() {
        try {
            yg = YgService.getCurrentYg();
            gsId = YgService.getCurrentYgGsId();
            zggsId = YgService.getCurrentYgZgGsId();
            if (xsdId != null) {
                xsd = this.ckshService.findXsd(xsdId);
            } else {
                xsdhm = this.bmService.getXsdbmO("KCLS", null, gsId);
                this.startDate = new Date();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return SUCCESS;
    }

    @Action("check_cksh")
    public void editCksh() {
        try {
            ckshService.checkCksh(xsd);
            renderText("{\"statusCode\":\"200\", \"message\":\"出库审核成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("cksh_xsmx")
    public void chshDetail() {
        this.renderJson(this.ckshService.findCkshmxDetail(xsdId));
    }

    @Action("slsh_xsmx")
    public void slshXsmx() {
        this.renderJson(this.ckshService.findZddhmxDetail(xsdId));
    }

    @Action("slsh_sh")
    public void slsh_sh() {
        try {
            ckshService.slsh(xsdId);
            renderJson("{\"statusCode\":200}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":300,\"message\":\"" + e.getMessage() + "\"}");
        }
    }
    //=========getter===setter====================

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getYps() {
        return yps;
    }

    public void setYps(String yps) {
        this.yps = yps;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getWzbm() {
        return wzbm;
    }

    public void setWzbm(String wzbm) {
        this.wzbm = wzbm;
    }

    public String getXsdh() {
        return xsdh;
    }

    public void setXsdh(String xsdh) {
        this.xsdh = xsdh;
    }

    public Long getKhId() {
        return khId;
    }

    public void setKhId(Long khId) {
        this.khId = khId;
    }

    public Long getXsgsId() {
        return xsgsId;
    }

    public void setXsgsId(Long xsgsId) {
        this.xsgsId = xsgsId;
    }

    public Long getCkId() {
        return ckId;
    }

    public void setCkId(Long ckId) {
        this.ckId = ckId;
    }

    public Date getZdrqStart() {
        return zdrqStart;
    }

    public void setZdrqStart(Date zdrqStart) {
        this.zdrqStart = zdrqStart;
    }

    public Date getZdrqEnd() {
        return zdrqEnd;
    }

    public void setZdrqEnd(Date zdrqEnd) {
        this.zdrqEnd = zdrqEnd;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Long getGsId() {
        return gsId;
    }

    public void setGsId(Long gsId) {
        this.gsId = gsId;
    }

    public Long getZggsId() {
        return zggsId;
    }

    public void setZggsId(Long zggsId) {
        this.zggsId = zggsId;
    }

    public Yg getYg() {
        return yg;
    }

    public void setYg(Yg yg) {
        this.yg = yg;
    }

    public Xsd getXsd() {
        return xsd;
    }

    public void setXsd(Xsd xsd) {
        this.xsd = xsd;
    }

    public Bm getXsdhm() {
        return xsdhm;
    }

    public void setXsdhm(Bm xsdhm) {
        this.xsdhm = xsdhm;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Long getXsdId() {
        return xsdId;
    }

    public void setXsdId(Long xsdId) {
        this.xsdId = xsdId;
    }

    public String getCkshbz() {
        return ckshbz;
    }

    public void setCkshbz(String ckshbz) {
        this.ckshbz = ckshbz;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    public String getYck() {
        return yck;
    }

    public void setYck(String yck) {
        this.yck = yck;
    }

    public Date getCksjStart() {
        return cksjStart;
    }

    public void setCksjStart(Date cksjStart) {
        this.cksjStart = cksjStart;
    }

    public Date getCksjEnd() {
        return cksjEnd;
    }

    public void setCksjEnd(Date cksjEnd) {
        this.cksjEnd = cksjEnd;
    }

    @Autowired
    public void setCkshService(CkshService ckshService) {
        this.ckshService = ckshService;
    }

    @Autowired
    public void setBmService(BmService bmService) {
        this.bmService = bmService;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }
}
